using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace GameLogic
{
    public class ApiDefinition
    {
        public string Name { get; set; }
        public Type Pakcet { get; set; }

        public ApiDefinition(string Name, Type Pakcet)
        {
            this.Name = Name;
            this.Pakcet = Pakcet;
        }
    }

    /// <summary>
    /// 定义了所有的公共Socket API，分发送和接收，包含Base、Match、Lobby等
    /// </summary>
    public partial class SocketAPI
    {
        public static Dictionary<(Type, uint), ApiDefinition> SocketGetAPI = new Dictionary<(Type, uint), ApiDefinition>
        {
            #region 注册基础API（API_ID_BASE）
            { APIGenerator(API_ID_BASE.BUILD_LINK), new ApiDefinition("可以创建连接",  typeof(OnBuildLinkPacket)) },
            { APIGenerator(API_ID_BASE.ON_GET_ANONYMOUS_ID), new ApiDefinition("反馈获取匿名访问ID", typeof(OnGetAnonymousIDPacket)) },
            { APIGenerator(API_ID_BASE.ON_SOCKET_LOGIN), new ApiDefinition("反馈登录",typeof(OnSocketLoginPacket)) },
            { APIGenerator(API_ID_BASE.ON_SIGN_OUT), new ApiDefinition("反馈登出",typeof(OnSignOutPacket)) },
            { APIGenerator(API_ID_BASE.SERVICE_ERROR), new ApiDefinition("服务器错误",typeof(OnServiceErrorPacket)) },
            { APIGenerator(API_ID_BASE.ON_WECHAT_CODE_AUTHORIZE), new ApiDefinition("反馈微信code授权信息",typeof(OnWechatCodeAuthorizePacket)) },
            #endregion

            #region 注册代理API（API_ID_AGENT）
            {  APIGenerator(API_ID_AGENT.ON_USER_EXTRA_INFO), new ApiDefinition("用户额外信息推送",typeof(OnUserExtraInfoPacket)) },
            {  APIGenerator(API_ID_AGENT.AGENT_DATA_PUSH_INFO), new ApiDefinition("推送数值信息",typeof(OnAgentDataPushPacket)) },
            {  APIGenerator(API_ID_AGENT.GROW_CHANGED), new ApiDefinition("个人数据变化",typeof(GrowChangedPakcet)) },
            {  APIGenerator(API_ID_AGENT.DRESS_INFO), new ApiDefinition("推送装扮消息",typeof(DressInfoPakcet)) },
            #endregion

             #region 注册比赛API（API_ID_MATCH）
            { APIGenerator(API_ID_MATCH.ON_ENTER_MATCH), new ApiDefinition("反馈进入比赛", typeof(OnEnterMatchPacket)) },
            { APIGenerator(API_ID_MATCH.USER_EXIT_SERVER), new ApiDefinition("用户离开服务器", typeof(UserExitServerPacket)) },
            { APIGenerator(API_ID_MATCH.MATCH_BREAK_OFF), new ApiDefinition("比赛宕机", typeof(MatchBreakOffPacket)) },
            { APIGenerator(API_ID_MATCH.USER_EXIT_GAME), new ApiDefinition("用户退出比赛", typeof(UserExitGamePacket)) },
            //{ APIGenerator(API_ID_MATCH.ON_SEND_OPEN_PROP), new ApiDefinition("反馈获取道具列表", typeof(OnSendOpenPropPacket)) },
            //{ APIGenerator(API_ID_MATCH.ON_USE_PROP), new ApiDefinition("反馈使用道具请求", typeof(OnUsePropPacket)) },
            //{ APIGenerator(API_ID_MATCH.ON_USE_PROP_NOTICE), new ApiDefinition("使用道具请求通知", typeof(OnUsePropNoticePacket)) },
            //{ APIGenerator(API_ID_MATCH.CHAT_MESSAGE), new ApiDefinition("客户端发送表情", typeof(ChatMessagePacket)) },
            //{ APIGenerator(API_ID_MATCH.ON_CHAT_MESSAGE), new ApiDefinition("客户端接收互动消息", typeof(OnChatMessagePacket)) },
            //{ APIGenerator(API_ID_MATCH.ON_FLOP_BASE_SCORE), new ApiDefinition("反馈请求翻翻乐底分", typeof(OnFlopBaseScorePacket)) },
            { APIGenerator(API_ID_MATCH.USER_PAY_RESULT), new ApiDefinition("用户消费结果（翻翻乐）", typeof(UserPayResultPacket)) },
            { APIGenerator(API_ID_MATCH.ON_GENERAL_ERROR), new ApiDefinition("新比赛服通用错误", typeof(OnGeneralErrorPacket)) },
            { APIGenerator(API_ID_MATCH.PLAYER_DRESS_INFO_GAME), new ApiDefinition("比赛内玩家装扮信息", typeof(PlayerDressInfoGamePacket)) },
            { APIGenerator(API_ID_MATCH.GAME_ROUND_INFO), new ApiDefinition("回合信息", typeof(GameRoundInfoPacket)) },
            { APIGenerator(API_ID_MATCH.DATA_PUSH_INFO), new ApiDefinition("数值推送", typeof(DataPushInfoPacket)) },
            //{ APIGenerator(API_ID_MATCH.ON_GET_ROUND_END_STATISTICS_DATA), new ApiDefinition("回合结束统计信息", typeof(OnGetRoundEndStatisticsDataPacket)) },
            { APIGenerator(API_ID_MATCH.TRANSPARNET_DATA), new ApiDefinition("透传JSON数据", typeof(TransparentDataPacket)) },
            { APIGenerator(API_ID_MATCH.GET_PLAYER_INFO), new ApiDefinition("获取玩家信息", typeof(GetPlayerInfoListPakcet)) },
            { APIGenerator(API_ID_MATCH.GET_PLAYER_STATE), new ApiDefinition("获取桌上的玩家状态数据", typeof(GetPlayerStateListPakcet)) }
            //{ APIGenerator(API_ID_MATCH.COMPOSITE_PACKAGE), new ApiDefinition("复合包", typeof(CompositePackagePacket)) },
            #endregion
        };

        public static Dictionary<(Type, uint), ApiDefinition> SocketSendAPI = new Dictionary<(Type, uint), ApiDefinition>
        {
            //基础api
            {  APIGenerator(API_ID_BASE.BUILD_LINK), new ApiDefinition("请求创建连接", typeof(BuildLinkPacket)) },
            {  APIGenerator(API_ID_BASE.GET_ANONYMOUS_ID), new ApiDefinition("获取匿名访问ID", typeof(GetAnonymousIDPacket)) },
            {  APIGenerator(API_ID_BASE.SOCKET_LOGIN), new ApiDefinition("登录",typeof(SocketLoginPacket)) },
            {  APIGenerator(API_ID_BASE.SIGN_OUT), new ApiDefinition("登出",typeof(SignOutPacket)) },
            {  APIGenerator(API_ID_BASE.WECHAT_CODE_AUTHORIZE), new ApiDefinition("微信code授权信息",typeof(WechatCodeAuthorizePacket)) },
          
            //比赛api
            { APIGenerator(API_ID_MATCH.ENTER_MATCH), new ApiDefinition("进入比赛", typeof(EnterMatchPacket)) },
            { APIGenerator(API_ID_MATCH.EXIT_MATCH), new ApiDefinition("退出比赛", typeof(ExitMatchPacket)) },
            //{ APIGenerator(API_ID_MATCH.SEND_OPEN_PROP), new ApiDefinition("请求获取道具列表", typeof(SendOpenPropPacket)) },
            //{ APIGenerator(API_ID_MATCH.USE_PROP), new ApiDefinition("使用道具请求", typeof(UsePropPacket)) },
            //{ APIGenerator(API_ID_MATCH.ASK_FLOP_BASE_SCORE), new ApiDefinition("请求翻翻乐底分", typeof(AskFlopBaseScorePacket)) },
        };

        public static (Type, uint) APIGenerator<T>(T id) where T : Enum
        {
            return (typeof(T), Convert.ToUInt32(id));
        }
    }
}
